package com.example.expresshelp.service;

import java.util.ArrayList;
import java.util.List;

import org.jsoup.helper.Validate;

import android.content.Context;
import android.database.Cursor;

import com.example.expresshelp.bean.Address;
import com.example.expresshelp.bean.City;
import com.example.expresshelp.bean.Province;
import com.example.expresshelp.db.MySqliteHelper;
import com.example.expresshelp.util.Constance;
import com.example.expresshelp.util.Validator;

public class AddressService {
	private static final String TAG = "AddressService";

	/**
	 * 得到所有的地址信息
	 * 
	 * @return
	 */
	public static List<Address> getAddress(Context context, String query) {
		List<Address> addressList = new ArrayList<Address>();
		List<Address> pList = ProvinceService.getProvinceByName(context, query);
		if (pList != null) {
			addressList.addAll(pList);
		}
		List<Address> cList = CityService.getCityByName(context, query);
		if (cList != null) {
			addressList.addAll(cList);
		}
		List<Address> dList = DistrictService.getDistrictByName(context, query);
		if (dList != null) {
			addressList.addAll(dList);
		}
		List<Address> tList = TowntrService.getTowntrByName(context, query);
		if (tList != null) {
			addressList.addAll(tList);
		}
		/*List<Address> vList = VillagetrService.getVillagetrByName(context,
				query);
		if (vList != null) {
			addressList.addAll(vList);
		}*/

		/*
		 * List<Province> provinceList = null; Address address = new Address();
		 * //todo 设定只查北京 String where = " 1=1"; if
		 * (Validator.isEffective(query)) { where += " and name like '%" + query
		 * + "%'"; } Cursor cursor = MySqliteHelper.getInstance(context).query(
		 * Constance.PROVINCE_TABLE_NMAE, where); if (cursor != null) {
		 * provinceList = new ArrayList<Province>(); while (cursor.moveToNext())
		 * { Province province = new Province(); String code =
		 * cursor.getString(cursor.getColumnIndex("code"));
		 * province.setCode(code);
		 * province.setName(cursor.getString(cursor.getColumnIndex("name")));
		 * List<City> cityList = CityService.getCityByPcode(context, code);
		 * province.setCityList(cityList); provinceList.add(province); }
		 * address.setProvinceList(provinceList); }
		 */
		return addressList;
	}

}
